<template>
  <section class="result-main">
    <section class="main-buttons">
      <section class="main-buttons-title">
        <span>投票结果：</span>
        <span>
          一共投票次数为
          <span class="num">{{ ps }}</span> 人数为
          <span class="num">{{ rs }}</span>
        </span>
      </section>
      <section class="main-buttons-btns" />
      <!-- <el-button style="margin-left: 10px" @click="handleExport"
        >批量导出</el-button
      >-->
      <el-button type="primary" style="margin-left: 10px" @click="back()">返回</el-button>
    </section>

    <section class="main-table">
      <v-table
        :list="list"
        tag="voteResult"
        :sourceArr="['img']"
        :list-loading="listLoading"
        :filter-column="filtercolumn"
      ></v-table>
    </section>
  </section>
</template>
<script>
import Pagination from '@/components/Pagination'
import VTable from '@/components/Table'
import { queryResult } from '../api/index'
import permission from '@/directive/permission/index.js'

export default {
  name: 'resultindex',
  components: { Pagination, VTable, },
  directives: { permission },
  data() {
    return {
      list: [],
      listLoading: false,
      id: '',
      view: '/API-DOCUMENT/document/file/download?id=',
      ps: 0,
      rs: 0
    }
  },
  created() {
    if (this.$route.query.i) {
      this.id = this.$route.query.i
      this.getList()
    } else {
      this.$message.error('参数错误')
      this.$router.back()
    }

  },
  methods: {
    filtercolumn(scope, item) {
      if (item === 'img') {
        return `${this.view + scope.row['coverImgId']}`
      }
      return scope.row[item]
    },
    back() {
      this.$router.back()
    },
    sumFun() {
      this.list.forEach(e => {
        this.ps += parseInt(e.selectedNumber)
        this.rs += parseInt(e.voteCount)
      });
    },
    getList(obj) {
      this.listLoading = true
      return new Promise((resolve, reject) => {
        queryResult({ id: this.id }).then(response => {
          this.list = response.data.data
          this.sumFun()
          this.listLoading = false
        }).catch(error => {
          reject(error)
          this.listLoading = false
        })
      })
    },
    handleExport() {

    }
  }
}
</script>
<style lang="scss">
@import "@/styles/mixin.scss";

.result-main {
  padding: 10px;
  .main-search {
    background-color: #fff;
    padding: 0 10px;
    .svg-container {
      padding: 0 5px 0 10px;
      color: #bfced6;
      vertical-align: middle;
      display: inline-block;
    }
    .search-input {
      width: 60%;
      position: relative;
      &:after {
        content: "";
        position: absolute;
        left: -25px;
        right: 0;
        bottom: 8px;
        height: 1px;
        background: rgba(226, 227, 232, 1);
      }
      input {
        outline: none;
        background: transparent;
        border: none;
        outline: medium;
        padding: 0;
        &:focus {
          outline: none;
          background-color: transparent;
        }
      }
    }
    .search-btn {
      display: inline-block;
      float: right;
      .el-button.is-round {
        padding: 10px 30px;
        margin-right: 34px;
      }
      .search-more {
        font-size: 14px;
        font-weight: 500;
        @include font-color($mainColor);
        cursor: pointer;
        margin-left: 10px;
      }
    }

    &.merge {
      height: 50px;
      line-height: 50px;
    }

    &.separate {
      .search-inner {
        padding-top: 10px;
        .search-inner-item {
          .item-label {
            height: 30px;
            line-height: 30px;
            font-size: 14px;
            color: #a6a6a6;
            font-weight: 400;
          }
          .el-input {
            position: relative;
            &.el-date-editor input {
              padding-left: 30px;
            }
            .el-input__inner {
              border: none;
              padding: 0;
            }
            &:after {
              content: "";
              height: 1px;
              background-color: #e2e3e8;
              position: absolute;
              left: 0;
              right: 0;
              bottom: 0;
            }
          }
        }
      }
      .search-btn {
        text-align: center;
        display: block;
        float: none;
        height: 56px;
        line-height: 56px;
      }
    }
  }
  .classify-tab {
    width: 100%;
    margin: 10px 0;
    padding: 0 10px;
    background-color: #fff;
    display: flex;
    border-radius: 4px;
    .el-tabs__nav-wrap::after {
      display: none;
    }
    .el-tabs__header {
      margin: 0;
    }
  }
  .main-buttons {
    display: flex;
    line-height: 36px;
    margin-top: 10px;
    .main-buttons-title {
      flex: 1;
      height: 36px;
      line-height: 36px;
      font-size: 16px;
      font-weight: bold;
      color: rgba(51, 51, 51, 1);
      .num {
        @include font-color($mainColor);
      }
    }
  }
}
</style>
